package icu.hsu.apisdk.config;

import icu.hsu.apisdk.client.HsuApiClient;
import icu.hsu.apisdk.service.ApiService;
import icu.hsu.apisdk.service.impl.ApiServiceImpl;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * Hsu API客户端配置
 * @ClassName: HsuApiClientConfig
 * @author Hsu琛君珩
 * @date 2024-09-08
 * @apiNote
 * @Version: v1.0
 */
@Data
@Configuration
@ConfigurationProperties("hsu.api.client")
@ComponentScan
public class HsuApiClientConfig {
    /**
     * 访问密钥
     */
    private String accessKey;

    /**
     * 秘密密钥
     */
    private String secretKey;

    /**
     * 网关
     */
    private String host;

    @Bean
    public HsuApiClient hsuApiClient() {
        return new HsuApiClient(accessKey, secretKey);
    }

    @Bean
    public ApiService apiService() {
        ApiServiceImpl apiService = new ApiServiceImpl();
        apiService.setHsuApiClient(new HsuApiClient(accessKey, secretKey));
        if (StringUtils.isNotBlank(host)) {
            apiService.setGatewayHost(host);
        }
        return apiService;
    }
}
